﻿niggles.Register({
    Initialise: function (niggles) {
        var me = this;
        niggles._snippets.login.Execute = function () { me.Execute(niggles, $(niggles._snippets.login)) };
    },
    Execute: function (niggles, loginSnippet) {
        var me = this;
        var control = $(loginSnippet.html());
        var form = control.find('form');
        var cancel = $(form.find('input[name=cancel]')[0]);
        var txtUsername = $(form.find('input[name=username]')[0]);
        form.submit(function () {
            me._login(niggles, txtUsername);
            me.PostExecute(niggles, control);
            return false;
        });
        cancel.click(function () {
            me.PostExecute(niggles, control);
            return false;
        });
        $('#deck').append(control);
    },
    PostExecute: function (niggles, control) {
        control.remove();
    },
    _login: function (niggles, txtUsername) {
        niggles.SetLoginToken(txtUsername.val());
    }
});

